package com.mm.fiflter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * @author XiaoLuo
 * @ClassName: PaiZiFiflter
 * @Description: ${todo}
 * @date 2019/4/9 15:33
 */
@Component
public class PaiZiFiflter extends ZuulFilter {
	@Override public String filterType() {

		return "pre";
	}

	@Override public int filterOrder() {
		return 1;
	}

	/**
	 * 是否启用这个过滤器
	 * @return
	 */
	@Override public boolean shouldFilter() {
		return true;
	}

	@Override public Object run() throws ZuulException {

		RequestContext context = RequestContext.getCurrentContext();
		HttpServletRequest request = context.getRequest();
		String paizi = request.getParameter("paizi");


		if(StringUtils.isEmpty(paizi)){
			context.setSendZuulResponse(false);
			context.setResponseStatusCode(HttpStatus.UNAUTHORIZED.value());
		}

		return null;
	}
}
